import random
from datetime import datetime

#购前
money = 100
#商品列表
good_list = ['a','b','c','d','e','f','g','h','i','j']
#商品价格
good_price_list = [20,60,70,80,90,100,110,120,130,140]
#购物车
good_car_list = []
#折扣表
shop_coupon_list =[1,2,3,4,5,6,7,8,9,9]
#抽出来的折扣
coupon_list = []
#购中
a=0
i=0
#购物数量
count = 0
#总价
price_all = 0

#判定是否退出购物、是否退货
exit_shop = 1
shop_return = 0
while exit_shop == 1:
    good_want = input("您要购买什么商品？\n")
    for i in range(10):
        good = good_list[i]
        price = good_price_list[i]
        coupon = random.choice(shop_coupon_list)
        if good_want in good_list and good_want == good:
             if money >= price*coupon*0.1:
                print("恭喜你，抽到了", coupon, "折")
                coupon_list.append(coupon)
                good_car_list.append(good)
                print("购物车中的商品有",good_car_list)

                money -= price * coupon * 0.1
                local_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                print("恭喜，购买成功！您的卡余额还剩",money,"元")
                count += 1
                price_all += price*coupon*0.1
                shop_return = int(input("是否从购物车中移除商品，输入1移除，输入0不移除\n"))
                if shop_return == 1:  # 退货
                    re_good = int(input("输入您要移除的货物编号:\n"))
                    good_car_list.remove(good_car_list[re_good-1])
                    money += good_price_list[re_good-1] * coupon_list[re_good-1] * 0.1
                    count -= 1
                    price_all -= good_price_list[re_good-1] * coupon_list[re_good-1] * 0.1
                print("购物车中的商品有", good_car_list)
                exit_shop = int(input("输入1继续购物，输入0退出购物：\n"))
                break
             else :
                print("恭喜你，抽到了", coupon, "折")
                print("穷鬼，钱不够！请到其他超市购买！")
                exit_shop = 0
                break
        else:
            if good_want not in good_list:
                print("没有这个商品，别瞎弄！")
                break
#购后
shop_exit = input("输入q退出：")
if shop_exit == 'q':
    print("购物小条\n",
          "购物时间",local_time,"\n"
          "余额",money,"元\n"
          "购物数量",count,"\n"
          "总价值",price_all,"元")

